from typing import *
from math import inf


class Solution:
    def maximumTotalSum(self, maximumHeight: List[int]) -> int:
        maximumHeight.sort()
        ans, c = 0, inf
        for i in range(len(maximumHeight) - 1, -1, -1):
            c = min(c - 1, maximumHeight[i])
            ans += c
            if c <= 0:
                return -1
        return ans


so = Solution()
print(so.maximumTotalSum([6, 6, 6, 3, 7, 2, 6, 5]))
